#define  _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <limits.h>

#define MAXN 100
#define INF INT_MAX

int dist[MAXN][MAXN];
int next[MAXN][MAXN];
int graph[MAXN][MAXN];
int N, M;

void floydWarshall() {
    int min_cycle = INF;
    int start = -1, end = -1;

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (dist[i][k] != INF && dist[k][j] != INF && dist[i][j] != INF &&
                    dist[i][k] + dist[k][j] < dist[i][j]) {
                    dist[i][j] = dist[i][k] + dist[k][j];
                    next[i][j] = next[i][k];
                }
            }
        }

        // Check for the minimum cycle
        for (int i = 0; i < N; i++) {
            if (dist[i][i] < min_cycle) {
                min_cycle = dist[i][i];
                start = i;
                end = i;
            }
        }
    }

    if (min_cycle == INF) {
        printf("No solution.\n");
    }
    else {
        // Reconstruct the cycle
        int path[MAXN];
        int path_len = 0;
        int u = start;
        do {
            path[path_len++] = u;
            u = next[u][end];
        } while (u != end);
        path[path_len++] = end;

        for (int i = 0; i < path_len; i++) {
            printf("%d ", path[i] + 1); // +1 to convert to 1-based index
        }
        printf("\n");
    }
}

int main() {
    scanf("%d %d", &N, &M);

    // Initialize the graph
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            graph[i][j] = INF;
            dist[i][j] = INF;
            next[i][j] = -1;
        }
        graph[i][i] = 0;
        dist[i][i] = 0;
    }

    // Read the edges
    for (int i = 0; i < M; i++) {
        int u, v, l;
        scanf("%d %d %d", &u, &v, &l);
        u--; v--; // Convert to 0-based index
        graph[u][v] = l;
        graph[v][u] = l;
        dist[u][v] = l;
        dist[v][u] = l;
        next[u][v] = v;
        next[v][u] = u;
    }

    floydWarshall();

    return 0;
}